#include "stdafx.h"
#include "Wave.h"

CPen Wave::pen1;
CPen Wave::pen2;
CPen Wave::pen3;
CPen Wave::pen01;
CPen Wave::pen02;
CPen Wave::pen03;

//////////////////////////////////////////////////////////////////////
// Wave::Coord
//////////////////////////////////////////////////////////////////////

Wave::Coord::Coord()
{
   m_step.x=m_step.y=1;
}

Wave::Coord::~Coord()
{
}

CPoint Wave::Coord::ScreenAt(int x, int y)
{
   CPoint point;
   CPoint o = GetOO();

   point.x = o.x + x * m_step.x;
   point.y = o.y + y * m_step.y;

   return point;
}

void Wave::Coord::GetXYAt(CPoint point, int &x, int &y)
{
   CPoint o = GetOO();

   x = (point.x-o.x)/m_step.x;
   y = (point.y-o.y)/m_step.y;
}

void Wave::Coord::Init(CRect rect)
{
   m_o.x = rect.left+15;
   m_o.y = rect.bottom/2+50;

   m_extend.x = rect.right - m_o.x;
   m_extend.y = rect.bottom;
}

void Wave::Coord::DrawCoord(CDC *pDC)
{
   //line
   CPen *pOldPen = pDC->SelectObject(&Sheet::txpen);

   //draw
   pDC->MoveTo(m_o.x, 0);
   pDC->LineTo(m_o.x, m_extend.y);
   pDC->MoveTo(m_o.x, m_o.y);
   pDC->LineTo(m_o.x+m_extend.x, m_o.y);

   pDC->SelectObject(pOldPen);
}


//////////////////////////////////////////////////////////////////////
// Wave
//////////////////////////////////////////////////////////////////////

Wave::Wave()
{
   pen1.CreatePen (PS_SOLID, 1, Sheet::colorYellow);
   pen2.CreatePen (PS_SOLID, 1, Sheet::colorCyan);
   pen3.CreatePen (PS_SOLID, 1, Sheet::colorPurpl);
   pen01.CreatePen(PS_DOT,   1, Sheet::colorYellow);
   pen02.CreatePen(PS_DOT,   1, Sheet::colorCyan);
   pen03.CreatePen(PS_DOT,   1, Sheet::colorGreen);
}

Wave::~Wave()
{
   pen1.DeleteObject();
   pen2.DeleteObject();
   pen3.DeleteObject();
   pen01.DeleteObject();
   pen02.DeleteObject();
   pen03.DeleteObject();
}


void Wave::ShowWave(int Option, CDC *pDC, NumQueue *datas)
{
}

void Wave::ShowP2Wave(CDC *pDC, NumQueue *datas)
{
   float xscale=1.0;
   float yscale=5.0;
  
   CPoint o = coord.GetOO();
   
   CPen *pOldPen = pDC->SelectObject(&pen1);
   int x=0,y=0;
   int prey=-1;
   pDC->MoveTo(o.x+5, o.y);
   int count = datas->count();
   for(int i=500; i<count; i++)
   {
      Num num(datas->GetAt(i));
      if(num.IsRed()){
         y--;
         if(prey==1) x+=5;
         prey=0;
      }
      else if(num.IsBlack()){
         y++;
         if(prey==0) x+=5;
         prey=1;
      }

      pDC->SetPixel(o.x+5+x*xscale, o.y+y*yscale, Sheet::colorText);
      pDC->LineTo(o.x+5+x*xscale, o.y+y*yscale);
   }

   pOldPen = pDC->SelectObject(&pen2);
   y=0;
   pDC->MoveTo(o.x+5, o.y);
   for(i=0; i<count; i++)
   {
      Num num(datas->GetAt(i));
      if(num.IsOdd())
         y--;
      else if(num.IsEven())
         y++;

      pDC->SetPixel(o.x+5+i*xscale, o.y+y*yscale, Sheet::colorText);
      pDC->LineTo(o.x+5+i*xscale, o.y+y*yscale);
   }

   pOldPen = pDC->SelectObject(&pen3);
   y=0;
   pDC->MoveTo(o.x+5, o.y);
   for(i=0; i<count; i++)
   {
      Num num(datas->GetAt(i));
      if(num.IsBig())
         y--;
      else if(num.IsSmall())
         y++;

      pDC->SetPixel(o.x+5+i*xscale, o.y+y*yscale, Sheet::colorText);
      pDC->LineTo(o.x+5+i*xscale, o.y+y*yscale);
   }
}

void Wave::ShowP3Ware(CDC *pDC, NumQueue *datas)
{
}

